function [ lm_avg,lm_num,lm_sum ] = mexLocalMaximaGBVS( data,thresh )

lm_avg=0;lm_num=0;lm_sum=0;
[m,n]=size(data);
for i=1:m
    for j=1:n
        a=0;b=0;c=0;d=0;
        if ((i>1)&&(j>1))
            a=data((i-1),j);
            c=data(i,(j-1));
        end
        if((i<m)&&(j<n))
            b=data((i+1),j);
            d=data(i,(j+1));
        end
        
        val=data(i,j);
        if ( val>=thresh && val>=a && val>=b && val>=c && val>=d)
            lm_num=lm_num+1;
            lm_sum=lm_sum+val;
        end
    end
end

if lm_sum>0
    lm_avg=lm_sum/lm_num;
else
    lm_avg=0;
end

        
end

